﻿using LPY.LeHealth.DAL;
using LPY.LeHealth.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LPY.LeHealth.Service
{
    /// <summary>
    /// 购物车
    /// </summary>
    public class CartService
    {
        private CartDal carDal;
        public CartService()
        {
            carDal = new CartDal();
        }

        public bool Add(Cart car)
        {
            long id;
            return carDal.Insert(car,out id);
        }

        public bool Add(int userId,int comboId,int count)
        {
            var car = new Cart()
            {
                UserId = userId,
                ComboId = comboId,
                Count = count
            };
            return Add(car);
        }

        public List<Cart> GetListByUserId(int id)
        {
            return carDal.SelectByUserId(id);
        }

        /// <summary>
        /// 删除购物车项
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteItem(int id)
        {
            return carDal.DeleteById(id);
        }

        /// <summary>
        /// 更改数量
        /// </summary>
        public bool UpdateCount(int id, int addCount, out int count)
        {
            var rtv= carDal.UpdateCount(id, addCount, out count);
            return rtv;
        }

        /// <summary>
        /// 清空用户购物车
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public bool Clear(int uid)
        {
            return carDal.Clear(uid);
        }
    }
}
